package com.buka.controller;

import com.buka.entity.Movie;
import com.buka.entity.MovieType;
import com.buka.service.MovieService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.util.List;

//   http://localhost:8080/mv/index
@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //展示首页  渲染电影列表

//        resp.sendRedirect("index.jsp");
        //转发
        //调用service 业务层，查询电影类型集合
        MovieService movieService = new MovieService();

        //去数据库查询电影类型集合
        List<MovieType> movieTypes = movieService.typeList();

        //向req对象中设置属性，属性名叫typeList   属性的值 是从数据库查询到的 电影类型集合
        req.setAttribute("typeList",movieTypes);


        //查询电影列表
        //声明 一个集合变量
        List<Movie> movieList = movieService.list();
        req.setAttribute("mList",movieList);

        //请求转发
        req.getRequestDispatcher("/index.jsp").forward(req,resp);

    }
}
